package com.service;

import com.config.RibbitMQConfig;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RabbitListener(queues = {"s20201_Queue1"})
public class MiashService {

    @Autowired
    private RabbitTemplate  rabbitTemplate;

    /**
     * 发送消息到队列
     * @param msg
     */
    public void sendMessage(String msg)
    {
         //交换机，路由key, 消息
         rabbitTemplate.convertAndSend("s20201_FanoutExchange",null,msg);
    }


    @RabbitHandler
    public void reciveMessage(String msg)
    {
        System.out.println("收到了消息:"+msg);
    }
}
